package com.demon.androidbasic.titlebar

import android.os.Build.VERSION_CODES
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.appcompat.widget.Toolbar
import com.demon.androidbasic.R

/**
 * 通用ToolBar
 *
 * Author : zhaozeyang
 * Date : 2020/8/21
 */
class CommonTitleBar(private val toolBar: Toolbar) : ITitleBar {
  override fun getTitleView(): TextView? = toolBar.findViewById(R.id.title_bar_title)

  override fun getImageRightBtnFirst(): ImageView? =
    toolBar.findViewById(R.id.title_bar_img_btn_right_first)

  override fun getImageRightBtnSecond(): ImageView? =
    toolBar.findViewById(R.id.title_bar_img_btn_right_second)

  override fun getBackBtn(): ImageView? = toolBar.findViewById(R.id.title_bar_btn_back)

  override fun showOrHide(show: Boolean) {
    toolBar.visibility = if (show) View.VISIBLE else View.GONE
  }

  @RequiresApi(VERSION_CODES.LOLLIPOP)
  override fun setToolbarElevation(elevation: Float) {
    toolBar.elevation = elevation
  }
}